
public class TestHeap {


    public static void createHeap(int[]array){
        for (int parent = (array.length-1-1)/2; parent >=0 ; parent--) {
            shiftDown(array,parent,array.length);
        }
    }
    public static void shiftDown(int[]array,int parent,int len){
        int child=2*parent+1;
        while(child<len){
            if(child+1<len&&array[child+1]>array[child]){
                child++;
            }
            if(array[parent]<array[child]){
                int tmp=array[child];
                array[child]=array[parent];
                array[parent]=tmp;
                parent=child;
                child=2*parent+1;
            }else{
                break;
            }
        }
    }

    public static void main(String[] args) {
        int []array={99,22,33,44,21,34,45,32};
        TestHeap testHeap=new TestHeap();
        testHeap.createHeap(array);
        System.out.println("===");
    }
}

